<?php
header('content-type:text/html;charset=utf8');
/**
 * Class UserController
 */
class UserController extends BaseController
{


    /**
     * 账户信息
     * @return mixed
     */
    public function UserAccount()
    {
      $info = UserService::instance()->UserAccount();
      return $this->view('index.user_account')->with('info',$info);
    }

    /**
     * 实名认证
     * @return mixed
     */
    public function UsernameAuthOne()
    {
        return $this->view('index.username_auth_one');
    }

    public function RealNameAuth()
    {
        if(Request::isMethod('post')){
            #收集信息
            $paramObj = new stdClass();
            $paramObj->real_name            =       $this->getParam('real_name');
            $paramObj->id_card              =       $this->getParam('id_card');


            #逻辑处理
            $rs = UserService::instance()->RealNameAuth($paramObj);
            if(empty($rs)){
                return 0;
            }else if($rs = 1){
                return 1;
            }else if($rs ==2){
                return 2;
            }
;
        }
    }


    public function UsernameAuthTwo()
    {
        $info = UserService::instance()->RealNameAuth();
        if(!empty($info))
        return $this->view('index.username_auth_two');
    }
    public function UsernameAuthThr()
    {
        return $this->view('index.username_auth_thr');
    }
    /**
     * 银行卡管理
     * @return mixed
     */
    public function UserBankcard()
    {
        $info = UserService::instance()->UserBankcard();
        return $this->view('index.user_bankcard')->with('info',$info);
    }

    /**
     * 添加银行卡
     * @return mixed
     */
    public function UserBankcardAdd()
    {
        return $this->view('index.user_bankcard_add');
    }

    /**
     * 绑定银行卡
     * @return mixed
     */
    public function UserBankcardBound()
    {
        if(Request::isMethod('post')){
           #收集信息
            $paramObj = new stdClass();
            $paramObj->bound_name           =       $this->getParam('bound_name');
            $paramObj->bank_num             =       $this->getParam('bank_num');
            $paramObj->bank_name            =       $this->getParam('bank_name');
            $paramObj->bound_mobile         =       $this->getParam('bound_mobile');

            #逻辑处理
            try{
                UserService::instance()->UserBankcardBound($paramObj);
                return Redirect::to('/user_bankcard');
            }catch(Exception $e){
                $this->rest->error($e->getMessage(),$e->getCode());
            }

        }
    }

    /**
     * 银行卡解绑
     * @return mixed
     */
    public function UserBankcardUnbound()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->bank_id = $this->getParam('bank_id');

        #逻辑操作
        $state = UserService::instance()->UserBankcardUnbound($paramObj);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     * 银行卡解绑ajax返回
     * @return mixed
     */
    public function BankcardUnboundAjax()
    {
        $info = UserService::instance()->UserBankcard();
        return $this->viewAjax('index.ajaxTemplates.user_bankcard_part')->with('info', $info);
    }

    /**
     * 密码管理
     * @return mixed
     */
    public function UserPassword()
    {
        return $this->view('index.user_password');
    }

    /**
     * 充值
     * @return mixed
     */
    public function UserMoney()
    {
        return $this->view('index.user_money');
    }

    /**
     * 提现
     * @return mixed
     */
    public function UserMoney_()
    {
        return $this->view('index.user_money_');
    }


    /**
     * 账户明细
     * @return mixed
     */
    public function UserAccountDetails()
    {
        $account = UserService::instance()->Account();
        return $this->view('index.user_account_details')->with(['account'=>$account]);

    }
    /**
     * 充值记录
     * @return mixed
     */
    public function UserRechargeRecord()
    {
        $recharge = UserService::instance()->Recharge();
        return $this->view('index.user_recharge_record')->with(['recharge'=>$recharge]);

    }
    /**
     * 提现记录
     * @return mixed
     */
    public function UserWithdrawRecord()
    {
        $withdraw = UserService::instance()->Withdraw();
        return $this->view('index.user_withdraw_record')->with(['withdraw'=>$withdraw]);

    }

    /**
     * 平台奖励
     * @return mixed
     */
    public function UserAward()
    {
        return $this->view('index.user_award');
    }

    /**
     * 邀请好友
     * @return mixed
     */
    public function UserInvite()
    {
        return $this->view('index.user_invite');
    }

    /**
     * 投资记录
     * @return mixed
     */
    public function UserInvestTicket()
    {
        $info = UserService::instance()->UserInvestTicket();
        return $this->view('index.user_invest_ticket')->with('info',$info);

    }

    /**
     * 报票记录
     * @return mixed
     */
    public function UserBTicket()
    {
        $info = UserService::instance()->UserBTicket();
        return $this->view('index.user_b_ticket')->with('info',$info);
    }


    /**
     * 消息列表
     * @return mixed
     */
    public function UserNewsList()
    {
        $read = UserService::instance()->Read();
        $unread = UserService::instance()->Unread();
        $all = UserService::instance()->ReadAll();

        return $this->view('index.user_news_list')->with(['read'=>$read,'unread'=>$unread,'all'=>$all]);

    }

    public  function UserNewsDel1()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->num  = $this->getParam('num');

        #逻辑操作
        UserService::instance()->UserNewsDel($paramObj);
        $all = UserService::instance()->ReadAll();
        return $this->viewAjax('index.ajaxTemplates.user_news1_part')->with(['all'=>$all]);
    }

    public function UserNewsDel2()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->num  = $this->getParam('num');

        #逻辑操作
        UserService::instance()->UserNewsDel($paramObj);
        $unread = UserService::instance()->UnRead();
        return $this->viewAjax('index.ajaxTemplates.user_news2_part')->with(['unread'=>$unread]);

    }

    public function UserNewsDel3()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->num  = $this->getParam('num');
        #逻辑操作
        UserService::instance()->UserNewsDel($paramObj);
        $read = UserService::instance()->Read();
        return $this->viewAjax('index.ajaxTemplates.user_news3_part')->with(['read'=>$read]);

    }
}